package service;

import java.util.List;


import common.DButil;
import vo.UserBean;

public class UserService {
	
	public  List<Object> getAll(){
		String sql="select username,state from user";
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,UserBean.class );
		db.close();
		return list;
	}
	public  void del(String name){
		String sql="DELETE from user where username='"+name+"'";
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
		//test
	}

	

	public  List<Object> get(String name){
		String sql="select username,level from user where username='"+name+"'";
		DButil db = DButil.getInstance();
		List<Object> list = db.excuteQuery(sql,UserBean.class);
		
		db.close();
		
		return list;
	}
	public  boolean get(String name,String psd){
		String sql="select username from user where username='"+name+"' and password='"+psd+"'";
		DButil db = DButil.getInstance();
		List<String[]> list = db.excuteQuery(sql);
		db.close();
		if(list.size()>0)
			return false;
		return true;
	}
	public  void insert(String username,String password,String email,String state){
		String sql="insert into user values('"+username+"','"+password+"','"+email+"','"+state+"','2')";
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
	}
	public  void update(String username,String password,String email,String state){
		String sql="update user set password='"+password+"',email='"+email+"',state='"+state+"' where username='"+username+"'";
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
	}

}
